<?php

namespace app\app\controller;

use app\app\model\ProjectCBSJModel;
use app\app\model\ProjectHTModel;
use app\app\model\ProjectKYPSModel;
use app\app\model\ProjectModel;
use app\app\model\ProjectPlanModel;
use app\app\model\ProjectRiskModel;
use app\app\model\ProjectStudyDesignModel;
use app\app\model\ProjectTDModel;
use app\app\model\ProjectWZModel;
use app\app\model\ProjectXMHZModel;
use app\BaseController;
use app\Request;


class ProjectCentre extends BaseController
{
    public function plan()
    {
        $project_id = input('project_id');
        $page_size = input('pageSize', '20');
        $list = ProjectPlanModel::where('project_id', $project_id)->paginate($page_size);
        $this->success('success', $list);
    }

    public function wz()
    {
        $project_id = input('project_id');
        $page_size = input('pageSize', '20');
        $list = ProjectWZModel::where('project_id', $project_id)->paginate($page_size);
        $this->success('success', $list);
    }

    public function risk()
    {
        $project_id = input('project_id');
        $project_name = input('projectName');
        $page_size = input('pageSize', '20');

        $where = "1=1";
        if (isset($project_id)) $where .= " AND project_id  ='" . $project_id . "'";
        if (isset($project_name)) $where .= " AND project_name  LIKE '%" . $project_name . "%'";
        $list = ProjectRiskModel::where($where)->paginate($page_size);
        $this->success('success', $list);
    }

    public function td()
    {
        $project_id = input('project_id');
        $page_size = input('pageSize', '20');
        $list = ProjectTDModel::where('project_id', $project_id)->paginate($page_size);
        $this->success('success', $list);
    }

    public function ht()
    {
        $project_id = input('project_id');
        $page_size = input('pageSize', '20');
        $list = ProjectHTModel::where('project_id', $project_id)->paginate($page_size);
        $this->success('success', $list);
    }

    public function krps()
    {
        $project_id = input('project_id');
        $project_info = ProjectModel::where('id', $project_id)->find();
        $list = ProjectKYPSModel::alias('a')->field('a.*,b.file_name,b.file_path,c.project_tz')
            ->where('a.project_id', $project_info['link_project_id'])
            ->leftjoin('sys_file_info b', 'b.file_id = a.project_kyps_file')
            ->leftjoin('t_project_gjjd c', 'c.project_id = a.project_id')
            ->find();
        $this->success('success', $list);
    }

    public function xmhz()
    {
        $project_id = input('project_id');
        $project_info = ProjectModel::where('id', $project_id)->find();
        $list = ProjectXMHZModel::alias('a')->field('a.*,b.file_name,b.file_path,c.project_tz')
            ->where('a.project_id', $project_info['link_project_id'])
            ->leftjoin('sys_file_info b', 'b.file_id = a.project_xmhz_file')
            ->leftjoin('t_project_gjjd c', 'c.project_id = a.project_id')
            ->find();
        $this->success('success', $list);
    }

    public function xmhzDetails()
    {
        $id = input('id');
        $list = ProjectXMHZModel::alias('a')->field('a.*,b.file_name,b.file_path,c.project_tz')
            ->leftjoin('sys_file_info b', 'b.file_id = a.project_xmhz_file')
            ->leftjoin('t_project_gjjd c', 'c.project_id = a.project_id')
            ->where('a.id', $id)
            ->find();
        $this->success('success', $list);
    }

    public function cbps()
    {
        $project_id = input('project_id');
        $page_size = input('pageSize', '20');
        $list = ProjectCBSJModel::where('project_id', $project_id)->paginate($page_size);
        $this->success('success', $list);
    }

    public function cbpsDetails()
    {
        $id = input('id');
        $list = ProjectCBSJModel::alias('a')->field('a.*,b.file_name,b.file_path,c.project_tz')
            ->leftjoin('sys_file_info b', 'b.file_id = a.file_id')
            ->leftjoin('t_project_gjjd c', 'c.project_id = a.project_id')
            ->where('a.id', $id)
            ->find();
        $this->success('success', $list);
    }


    public function yearPlan()
    {
        $list = array(
            'start_time' => '2021-12-05 22:12:01',
            'put_time' => '2021-12-06 10:45:40'
        );
        $this->success('success', $list);
    }


    public function report()
    {
        $list = array(
            'company_name' => '中国电力工程顾问集团华东电力设计院有限公司',
            'report_time' => '2021-12-06 10:45:40',
            'check_time' => '2021-12-06 10:45:40',
            'remark' => ''
        );
        $this->success('success', $list);
    }


//    public function projectList(){
//        $where[] = ['project_period', '<>', '3'];
//        $where[] = ['is_parent', '=', 0];
//        $start_time = date('Y-01-01 00:00:00', time());
//        $end_time = date('Y-12-31 23:59:59', time());
//        $where[] = ['tc_time', '>=', $start_time];
//        $where[] = ['kg_time', '<=', $end_time];
//        $list = ProjectModel::where($where)->select();
//        $this->success('success', $list);
//    }

    public function projectList()
    {
        $list = ProjectStudyDesignModel::select();
        $this->success('success', $list);
    }
}
